# -*- coding: utf-8 -*-
'''
Created on 13.06.2012
Prototype that draws a sequence chart.

First prototype:
+-------+   +-----+
| Alice |   | Bob |
+-------+   +-----+
    |   Bla    |
    +--------->+
    |  Ohja    |
    +<---------+
    |          |
+-------+   +-----+
| Alice |   | Bob |
+-------+   +-----+

@author: dominik
'''
from collections import namedtuple
import Image
from StringIO import StringIO
import prot01SequenceTheme
from prototypeRenderer import PrototypeRenderer

Action = namedtuple("Action", ["id", "from_actor", "to_actor", "text"])

def main():
    test_actors = ("Alfred", "Bernd", "Carla", "Daniela")
    test_actions = [
        Action("1", "Alfred", "Bernd", "Ich quatsche gerne ganz schön viel, aber das macht dir doch nichts?"),
        Action("2", "Bernd", "Alfred", "Ohja"),
        Action("4", "Bernd", "Carla", "Aber was meint er damit?"),
        Action("5", "Carla", "Bernd", "Moment."),
        Action("6", "Carla", "Daniela", "Hast du ne Ahnung?"),
        Action("7", "Daniela", "Alfred", "Hurrp de durrp. Peng peng"),
        Action("8", "Alfred", "Daniela", "Whatever."),
        Action("9", "Daniela", "Carla", "Ich gehe jetzt nach hause."),
    ]

    renderer = PrototypeRenderer(test_actors, test_actions, prot01SequenceTheme)
    image = renderer.get_image_surface()
    print "done"
    
    
    # Debug code to automatically open the rendered image.
    output = StringIO()
    image.write_to_png(output)
    output.seek(0)
    img = Image.open(output)
    img.show()

if __name__ == '__main__':
    main()
